package service

import (
	"context"

	"micro-svr/apps/s2/api"
	"micro-svr/apps/s2/internal/dao"

	"go-main/library/log"
)

// Service service.
type Service struct {
	dao dao.Dao
}

// New new a service and return.
func New(d dao.Dao) (s *Service, cf func(), err error) {
	s = &Service{
		dao: d,
	}
	cf = s.Close
	return
}

// SayHello grpc demo func.
func (s *Service) SayHello(ctx context.Context, req *api.HelloReq) (reply *api.EmptyRsp, err error) {
	reply = new(api.EmptyRsp)
	log.Infof(ctx, "say hello %s", req)
	return
}

// SayHelloURL bm demo func.
func (s *Service) SayHelloURL(ctx context.Context, req *api.HelloReq) (reply *api.HelloRsp, err error) {
	reply = &api.HelloRsp{
		Content: "hello s2" + req.Name,
	}
	log.Infof(ctx, "hello url %s", req)
	return
}

// Ping ping the resource.
func (s *Service) Ping(ctx context.Context, e *api.EmptyReq) (*api.EmptyRsp, error) {
	return &api.EmptyRsp{}, s.dao.Ping(ctx)
}

// Close close the resource.
func (s *Service) Close() {
}
